package com.hwl.demo15.service.impl;

import com.hwl.demo15.service.Company;

import java.util.ArrayList;

/**
 * 具体分公司类
 *
 * @author sentry
 * @since 2023-03-25
 */
public class ConcreteCompany extends Company {

    protected ArrayList<Company> children = new ArrayList<>();

    public ConcreteCompany(String name) {
        super(name);
    }

    @Override
    public void add(Company company) {
        children.add(company);
    }

    @Override
    public void remove(Company company) {
        children.remove(company);
    }

    @Override
    public void display(int depth) {
        for (int i = 0; i < depth; i++) {
            System.out.print("-");
        }

        System.out.println(name);
        for (Company child : children) {
            child.display(depth + 2);
        }
    }

    @Override
    public void lineOfDuty() {
        for (Company child : children) {
            child.lineOfDuty();
        }
    }
}
